package com.mj.haier.calc.repository;

import java.util.List;

import javax.transaction.Transactional;

import com.mj.haier.calc.domain.AzEncourage;
import com.mj.haier.calc.domain.AzEncourageGroupSettlement;

import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;


/**
 * Spring Data  repository for the AzEncourage entity.
 */
@SuppressWarnings("unused")
@Repository
public interface AzEncourageRepository extends JpaRepository<AzEncourage, Long> {

    @Modifying
    @Transactional
    @Query("update AzEncourage a set a.settleState = :#{#azEncourage.settleState}, " 
        + " a.gmtModified = :#{#azEncourage.gmtModified}, a.modifiedUser = :#{#azEncourage.modifiedUser} "
        + " where a.id = :#{#azEncourage.id}")
	int updateSettleState(@Param("azEncourage") AzEncourage azEncourage);

    @Modifying
    @Transactional
    @Query("update AzEncourage a set a.secondSettleState = :#{#azEncourage.secondSettleState}, " 
        + " a.gmtModified = :#{#azEncourage.gmtModified}, a.modifiedUser = :#{#azEncourage.modifiedUser} "
        + " where a.id = :#{#azEncourage.id}")
	int updateSecondSettleState(@Param("azEncourage") AzEncourage azEncourage);

    @Query(nativeQuery = true, value = "select g.encourage_object as encourageObject, g.trade_code as tradeCode, g.netpoint as netpoint,"
        + " g.source_name_code as sourceNameCode, m.COMPANY_CODE as companyCode, m.DEPARTMENT as department, m.DEPARTMENT_NAME as departmentName"
        + " FROM az_encourage g INNER JOIN az_encourage_cash h ON g.id = h.parent_id INNER JOIN bd_gvs_itemconfig m ON g.source_name_code = m.SOURCE_NAME_CODE"
        + " WHERE h.settle_batch_id = '0' AND g.encourage_type = 'JDZX' GROUP BY g.encourage_object, g.source_name_code ")
    List<AzEncourageGroupSettlement> findAzEncourageGroup();
}
